<?php

require_once '../config.php';
require_once '../functions.php';
function register(){
    
    if(empty($_POST['nick'])){
        $GLOBALS['message'] = '请检查昵称';
        return;
    }
    if(empty($_POST['email'])){
        $GLOBALS['message'] = '请检查用户名';
        return;
    }
    if(empty($_POST['password'])){
        $GLOBALS['message'] = '请检查密码';
        return;
    }

    $nick = $_POST['nick'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    $rows = book_execute("insert into users (id,slug,email,password)values (null,'$nick','$email','$password')");

    $GLOBALS['success'] = $rows > 0;
    $GLOBALS['message'] = $rows <= 0 ? '更新失败！' : '更新成功！';


    
    // header('Location: /admin/login.php');
}
if($_SERVER['REQUEST_METHOD'] ==='POST'){
    register();
}
var_dump($_POST);


?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign in &laquo; Admin</title>
    <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="/static/assets/css/login_css.css">
    
</head>
<body>
<div id="register">
        <form class="register_in" action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
                <h2>注册</h2>
                <?php if (isset($message)) : ?>
            <div class="alert alert-danger warn">
              <?php echo $message; ?>
            </div>
            <?php endif; ?>
                <div class="register_mo">
                    <label for="nick" class="sr-only">昵称</label>
                    <input id="nick" name="nick" type="nick" class="form-control" placeholder="昵称" autofocus value="">
                    <label for="email" class="sr-only">邮箱</label>
                    <input id="email" name="email" type="email" class="form-control" placeholder="邮箱" autofocus value="">
                    <label for="password" class="sr-only">密码</label>
                    <input id="password" name="password" type="password" class="form-control" placeholder="密码">
                    <button  class="btn btn-primary btn-block login_btn">注 册</button>     
                </div>    
        </form>
    </div>
</body>
</html>